import java.util.Scanner;

public class Test9 {
    static class Counter{
        //volatile 解决内存可见性
        volatile int flag = 0;
    }
    public static void main(String[] args) {
        Counter counter = new Counter();
        Thread thread = new Thread(){
            @Override
            public void run() {
                while (counter.flag == 0) {
                }
                System.out.println("循环结束");
            }
        };
        thread.start();
        Thread thread2 = new Thread(){
            @Override
            public void run() {
                Scanner scanner = new Scanner(System.in);
                System.out.println("情输入一个数字");
                counter.flag = scanner.nextInt();
            }
        };
        thread2.start();
    }
}
